global_defs {
   router_id ocp_vrrp
   enable_script_security
   script_user root
}

{% for instance in keepalived_instances %}
{% if instance.check_status_command is defined %}
vrrp_script chk_command_{{ instance.virtual_router_id }} {
   script "{{ instance.check_status_command }}"
   interval 2
   weight 2
}
{% endif %}

vrrp_instance {{ instance.name }} {
  interface {{ instance.interface }}
  virtual_router_id {{ instance.virtual_router_id }}
  priority {{ instance.priority }}
  advert_int {{ instance.advert_int }}
  state {{ instance.state }}
  virtual_ipaddress {
    {% for ip in instance.virtual_ipaddresses %}
    {{ ip }}
    {% endfor %}
  }
  {% if instance.check_status_command is defined %}
  track_script {
    chk_command_{{ instance.virtual_router_id }}
  }
  {% endif %}
  authentication {
    auth_type {{ instance.authentication.auth_type }}
    auth_pass {{ instance.authentication.auth_pass }}
  }
}
{% endfor %}
